<template>
	<view class="user-spread-income">
		<!-- Incom Details -->
		<block v-for="(item, index) in incomeList" :key="index">
			<view class="income-item">
				<view class="income-item-content">
					<!-- Explain -->
					<view class="income-item-explain">{{ item.source_type_text }}</view>
					<!-- Money -->
					<view class="income-item-money">
						<template v-if="item.money * 1 <= 0">
							<text class="normal">{{ splitDecimals(item.money, 2) }}</text>
						</template>
						<template v-else>
							<text class="ornament">{{ '+' + splitDecimals(item.money, 2) }}</text>
						</template>
					</view>
				</view>
				<!-- Date -->
				<view class="income-item-time">{{ item.create_time }}</view>
			</view>
		</block>
		
		<!-- Loading -->
		<loading-footer :status="status" slotEmpty>
			<view class="data-null column-center" slot="empty" style="padding-top: 200rpx">
				<image class="img-null" src="/static/images/order_null.png" />
				<text class="nr muted">暂无记录～</text>
			</view>
		</loading-footer>
	</view>
</template>


<script>
	import { spreadEarningsDetail } from '@/api/user'
	import { loadingType } from '@/utils/type'
	import { loadingFun } from "@/utils/tools"
	
	export default {
		data() {
			return {
				incomeList: [],					// 佣金明细列表
				page: 1,                        // 当前页数状态
				status: loadingType.LOADING,    // 当前加载状态
			}
		},
		
		methods: {
			// 保留两位小数
			splitDecimals(number, prec) {
				const list = (number + '').split('.');
				let integer = list[0];
				let decimals = list[1] || '';
				
				const LEN = decimals.length;
				for (let i = prec - LEN; i > 0; --i) decimals += '0'
				return integer + '.' + decimals.substr(0, prec) || '0';
			},
			
			// 获取明细列表数据
			getIncomeList() {

				loadingFun(
				    spreadEarningsDetail,
				    this.page,
				    this.incomeList,
				    this.status
				).then(res => {
				    if (!res) return;
				    this.page = res.page;
				    this.incomeList = res.dataList;
				    this.status = res.status;
				});
			}
			
		},
		
		onLoad() {
			this.getIncomeList();
		}
	}
</script>


<style scoped>
	.user-spread-income {
		padding: 20rpx 0;
	}
	
	.income-item {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 120rpx;
		padding: 20rpx 30rpx;
		background-color: #FFFFFF;
	}
	
	.income-item:nth-child(n+2) {
		border-top: 1px solid #E5E5E5;
	}
	
	.income-item-content {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.income-item-explain {
		font-size: 30rpx;
		color: #333333;
	}
	
	.income-item-money {
		font-size: 32rpx;
	}
	
	.income-item-time {
		font-size: 24rpx;
		color: #999999;
	}
</style>
